package blasthouse.states;

import java.util.Vector;

import org.newdawn.slick.geom.Vector2f;

import blasthouse.objects.CollisionWaypoint;
import blasthouse.objects.UpdatingGameElement;

public class Toolbox {
	public static float distanceBetween(Vector2f v1, Vector2f v2){
		return (float) Math.sqrt( ((v1.x - v2.x)*(v1.x - v2.x)) + ((v1.y - v2.y)*(v1.y - v2.y)) );
	}
	public static Vector2f directionFrom1To2(Vector2f v1, Vector2f v2){
		return new Vector2f(v2.x - v1.x, v2.y - v1.y);
	}	
	public static CollisionWaypoint closestNode( UpdatingGameElement uge, Vector<CollisionWaypoint> things){
		if ( things.size() < 1 ){ return new CollisionWaypoint(); }
		
		CollisionWaypoint closest = things.firstElement();
		
		for (CollisionWaypoint g : things) {
			if ( distanceBetween( g.getPosition(), uge.getCenter() ) < distanceBetween( closest.getPosition(), uge.getCenter() ) ){
				closest = g;
			}
		}
		
		return closest;
	}
}
